const fs = require('fs-extra');
const path = require('path');

function deleteFilesRecursively(directoryPath) {
  const files = fs.readdirSync(directoryPath);

  for (const file of files) {
    const filePath = path.join(directoryPath, file);
    const fileStats = fs.statSync(filePath);

    if (fileStats.isFile()) {
      const fileExtension = path.extname(file);
      
      if (
        fileExtension === '.js' || 
        fileExtension === '.d.ts' || 
        fileExtension === '.ts' ||
        fileExtension === '.bin' ) // delete config
      {
        fs.unlinkSync(filePath);
        console.log(`Deleted: ${filePath}`);
      }
    } else if (fileStats.isDirectory()) {
      deleteFilesRecursively(filePath);
    }
  }
}

let protoDirectoryPath = path.join(__dirname, '../project/extensions/mlagents/static/assets/Runtime/Grpc/CommunicatorObjects');
deleteFilesRecursively(protoDirectoryPath);
protoDirectoryPath = path.join(__dirname, '../project/extensions/mlagents/static/assets/ONNX/Generated/');
deleteFilesRecursively(protoDirectoryPath);

// const configDirectoryPath = path.join(__dirname, '../../', 'assets/config');
// deleteFilesRecursively(configDirectoryPath);
